package com.qjs.smterp.jpa;

import java.io.Serializable;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.qjs.smterp.model.Users;

@Repository("userDao")
public class UserDaoImpl extends AbstractHibernateDAOImpl<Users, Long>
		implements UserDao, Serializable {
	private static final long serialVersionUID = 1L;

	@Override
	public Users findByUserNameAndPass(String userName, String password) {
		String queryString = "from Users user "
				+ "where user.enabled =1 AND user.login =:userName AND user.pwd =:password";
		Query query = getSession().createQuery(queryString);
		query.setParameter("userName", userName);
		query.setParameter("password", password);
		Users user = (Users) query.uniqueResult();
		return user;
	}

	@Override
	protected Class<Users> getDomainClass() {
		return Users.class;
	}

	@Override
	public Users findByUserName(String userName) {
		Query query = getSession().getNamedQuery("Users.findByLogin");
		query.setParameter("login", userName);		
		Users user = (Users) query.uniqueResult();
		return user;
	}

}
